import { HttpException, HttpStatus, Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';
import { AuthWhiteList } from 'src/utils/config';
@Injectable()
export class AuthMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: () => void) {
    const index = AuthWhiteList.indexOf(req.url)
    if(index >= 0){
      next()
      return
    }
    if (!req.headers.token) {
      throw new HttpException('没有token',HttpStatus.FORBIDDEN)
    }
    next();
  }
}
